export const { CryptoJS, lightAppJssdk } = window;

export const Decrypt = (word, key) => {
  key = CryptoJS.enc.Utf8.parse(key); //转为128bit
  const srcs = CryptoJS.enc.Hex.parse(word); //转为16进制
  const str = CryptoJS.enc.Base64.stringify(srcs); //变为Base64编码的字符串
  const decrypt = CryptoJS.AES.decrypt(str, key, {
    mode: CryptoJS.mode.ECB,
    spadding: CryptoJS.pad.Pkcs7
  });
  return decrypt.toString(CryptoJS.enc.Utf8);
};


export const isEmpty = (value) => {
  value = value || '';
  return /^\s*$/g.test(value);
};


export const getSessionStorage = (key, defaultValue) => {
  let value = sessionStorage.getItem(key) || defaultValue;
  if (value) {
    try {
      value = JSON.parse(value);
    } catch (e) {
    }
  }
  return value
};

export default {
  lightAppJssdk,
  CryptoJS,
  Decrypt,
  isEmpty,
  getSessionStorage
}
